<?php
/*

	+===================================================+
	+ TUGGO Open Source Content Management System		+
	+ Developed by Paul Cheek (pcheek.com)				+
	+ All content copyright 2006 - All rights reserved	+
	+ Visit www.TUGGO.org for more info					+
	+===================================================+
	+ Development Version 0.5 (alpha)					+
	+ Distribution prohibited in alpha stages!			+
	+===================================================+
	+ Licensed under the GNU GPL - Please refer to the  +
	+ license information in the root directory of this +
	+ distribution.										+
	+===================================================+
	
*/
?>
<?php
function error() {
	$query = "SELECT * FROM pages WHERE title='Error'";
	$result = mysql_query($query) or die(mysql_error());
	$row = mysql_fetch_array($result);
	echo "<h2>" . $row['title'] . "</h2>" . "<p>" . $row['content'] . "</p>";// Include the page template
}
?>

  <div id="content">
 
<?php
if(isset($function)) {
	if($function == "page") { // If a page is requested...
 		if(isset($id)) {
 			$query = "SELECT * FROM pages WHERE id=$id";
			$result = mysql_query($query) or die(mysql_error());
			$row = mysql_fetch_array($result);

			echo "<h2>" . $row['title'] . "</h2>" . "<p>" . $row['content'] . "</p>";// Include the page template
		} else {
			error();
		}
	} elseif($function == "pagewww") { // If a page is requested...
 		if(isset($id)) {
 			$query = "SELECT * FROM pages WHERE wwwpath='" . $id . "'";
			$result = mysql_query($query) or die(mysql_error());
			$row = mysql_fetch_array($result);

			echo "<h2>" . $row['title'] . "</h2>" . "<p>" . $row['content'] . "</p>";// Include the page template
		} else {
			error();
		}
	} elseif($function == "blog") { // If the blog is requested...
		if(isset($_GET['start'])) {
		$start = $_GET['start'];
		} else {
		$start = "0";
		}
		
		$next = $start+10;
		
		if($start == "0") {
		$last = "X";
		} elseif($start <= "10") {
		$last = "0";
		} else {
		$last = $start-10;
		}
	
			$query = "SELECT * FROM blog WHERE status='yes' ORDER BY id DESC LIMIT " . $start . ", 10";
			$result = mysql_query($query) or die(mysql_error());
			
			while($row = mysql_fetch_array($result)) {
				echo "<a href='index.php?function=blogitem&id=" . $row['id'] . "' style='color: #666;'><h2>" . $row['title'] . "</h2></a>" . "<p>Posted in " . $row['category'] . " by " . $row['author'] . " on " . $row['lastupdate'] . "</p><p>" . $row['content'] . "</p><div style='border-bottom: 1px dotted #B8B8B8;'>&nbsp;</div>";// Include the page template
			}
			
			echo "<a href='index.php?function=blog&start=" . $next . "'>Next Page</a>";
			
			if($last == "X") {
			echo "";
			} else {
			echo "<a href='index.php?function=blog&start=" . $last . "'>Previous Page</a>";
			}
			
	} elseif($function == "blogitem") { // If the blog is requested...
			$query = "SELECT * FROM blog WHERE id=$id";
			$result = mysql_query($query) or die(mysql_error());
			
			$row = mysql_fetch_array($result);
				echo "<h2>" . $row['title'] . "</h2>" . "<p>Posted in " . $row['category'] . " by " . $row['author'] . " on " . $row['lastupdate'] . "</p><p>" . $row['content'] . "</p>";// Include the page template
	} elseif($function == "account") { // If an account is requested...
			$query = "SELECT * FROM users WHERE id=$id";
			$result = mysql_query($query) or die(mysql_error());
			
			$row = mysql_fetch_array($result);
				echo "<h2>" . $row['displayname'] . "</h2>" . "<p>" . $row['about'] . "</p>";// Include the page template
	} else {
	$query = "SELECT * FROM config WHERE id='4'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result);
$online = $row['value'];
	if($online == "1") {
		$query = "SELECT * FROM pages WHERE title='Home'";
		$result = mysql_query($query) or die(mysql_error());
		$row = mysql_fetch_array($result);
		echo "<h2>" . $row['title'] . "</h2>" . "<p>" . $row['content'] . "</p>";// Include the page template
	} else { 
		$query = "SELECT * FROM config WHERE id='5'";
		$result = mysql_query($query) or die(mysql_error());
		$row = mysql_fetch_array($result);
		echo "<h2>Website Offline!</h2>" . "<p>" . $row['value'] . "</p>";// Include the page template
	}
	}
} else { // If no function is requested...
	error();
}
?>

  </div></div>
 
